package com.hdoit.ares.web.advertisement.providers;

import java.util.ArrayList;
import java.util.List;

import com.hdoit.ares.logical.advertisement.model.AdvertisementLocation;
import com.hdoit.ares.logical.advertisement.service.IAdvertisementLocationService;
import com.tennetcn.common.aop.CommonApplicationContextUtil;
import com.tennetcn.common.message.ListItem;
import com.tennetcn.component.attribute.provider.ISingleOptionListProvider;
import com.tennetcn.web.cbase.providers.base.DataListProviderBase;

public class AdLocationIdListProvider extends DataListProviderBase implements ISingleOptionListProvider<ListItem>{

	@Override
	public List<ListItem> getDataList(Object viewData) {
		List<AdvertisementLocation> advertisementLocations =getAdvertisementLocations();
		if(advertisementLocations == null){return null;}
		List<ListItem> listItems = new ArrayList<ListItem>();
		//应该有一个请选择
		ListItem listItem = new ListItem();
		listItem.setText(" 请选择广告位");
		listItem.setValue("");
		listItems.add(listItem);
		
		
		for(AdvertisementLocation advertisementLocation:advertisementLocations){
			listItem = new ListItem();
			listItem.setText(advertisementLocation.getName() + " " +"["+advertisementLocation.getWidth() + "x" + advertisementLocation.getHeight() + "]");
			listItem.setValue(advertisementLocation.getId());
			listItems.add(listItem);
		}
		
		dataList = listItems;
		return listItems;
	}

	
	public List<AdvertisementLocation> getAdvertisementLocations() {
		IAdvertisementLocationService advertisementLocationService = CommonApplicationContextUtil.getCurrentContext().getBean(IAdvertisementLocationService.class);
		
		return  advertisementLocationService.queryList();
	}

}
